using Microsoft.AspNetCore.Mvc;
using ZR.Model.Business.Dto;
using ZR.Model.Business;
using ZR.Service.Business.IBusinessService;

//创建时间：2025-08-06
namespace ZR.Admin.WebApi.Controllers.Business
{
    /// <summary>
    /// 部门配置表
    /// </summary>
    [Route("business/Dept")]
    public class DeptController : BaseController
    {
        /// <summary>
        /// 部门配置表接口
        /// </summary>
        private readonly IDeptService _DeptService;

        public DeptController(IDeptService DeptService)
        {
            _DeptService = DeptService;
        }

        /// <summary>
        /// 查询部门配置表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "dept:list")]
        public IActionResult QueryDept([FromQuery] DeptQueryDto parm)
        {
            var response = _DeptService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询部门配置表详情
        /// </summary>
        /// <param name="DeptId"></param>
        /// <returns></returns>
        [HttpGet("{DeptId}")]
        [ActionPermissionFilter(Permission = "dept:query")]
        public IActionResult GetDept(long DeptId)
        {
            var response = _DeptService.GetInfo(DeptId);
            
            var info = response.Adapt<DeptDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加部门配置表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "dept:add")]
        [Log(Title = "部门配置表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddDept([FromBody] DeptDto parm)
        {
            var modal = parm.Adapt<Dept>().ToCreate(HttpContext);

            var response = _DeptService.AddDept(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新部门配置表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "dept:edit")]
        [Log(Title = "部门配置表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateDept([FromBody] DeptDto parm)
        {
            var modal = parm.Adapt<Dept>().ToUpdate(HttpContext);
            var response = _DeptService.UpdateDept(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除部门配置表
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete/{ids}")]
        [ActionPermissionFilter(Permission = "dept:delete")]
        [Log(Title = "部门配置表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteDept([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<long>(ids);

            return ToResponse(_DeptService.Delete(idArr));
        }

    }
}